package com.jxm.hutools;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.extra.compress.CompressUtil;
import cn.hutool.extra.compress.extractor.Extractor;
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
import org.junit.Test;

import java.io.File;

/**
 * @Author: jxm
 * @Description:
 * @Date: 2023-12-19 14:41
 * @Version: 1.0
 */
public class CompressUtilTest {

    //压缩
    @Test
    public void test1(){
        final File file = FileUtil.file("e:/test/compress/ss.zip"); //压缩后文件名称
        CompressUtil.createArchiver(CharsetUtil.CHARSET_UTF_8, ArchiveStreamFactory.ZIP, file)
                .add(FileUtil.file("e:/test/someFiles")) //需要压缩文件名称或者文件夹
                .finish()
                .close();
    }

    //解压
    @Test
    public void test2(){
        Extractor extractor = CompressUtil.createExtractor(
                CharsetUtil.defaultCharset(),
                FileUtil.file("e:/test/compress/ss.zip"));

        extractor.extract(FileUtil.file("e:/test/compress/test2/"));
    }
}
